package ro.jproject.imc;

//import java.awt.GridLayout;

import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;




@SuppressWarnings("serial")
public class StudentRegistrationGUI extends JFrame implements ActionListener {

	private JPanel mainPanel;
	private JButton save;
	private TextField textFieldFirstName;
	private TextField textFieldLastName;
	private JLabel lastNameLabel;
	private JLabel firstNameLabel;
	private JButton buttonExit;
	public String saveFirstName;
	public String saveLastName;
	
	/**
	 * Create the frame.
	 */
	public StudentRegistrationGUI() {
		setTitle("Student Registration");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 272, 220);
		
		mainPanel = new JPanel();
		save = new JButton("Save");
		textFieldFirstName = new TextField("", 1);
		firstNameLabel = new JLabel("First Name");
		lastNameLabel = new JLabel("Last Name");
		buttonExit = new JButton("Exit");
			
		mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		mainPanel.setLayout(null);
		
		textFieldFirstName.setBounds(98, 29, 124, 21);
		mainPanel.add(textFieldFirstName);
		textFieldLastName = new TextField("",1);
		textFieldLastName.setBounds(98, 66, 124, 21);
		mainPanel.add(textFieldLastName);
		
		save.setBounds(23, 134, 100, 21);
		mainPanel.add(save);
			
		setContentPane(mainPanel);
		
		firstNameLabel.setBounds(23, 29, 69, 14);
		mainPanel.add(firstNameLabel);
		
		lastNameLabel.setBounds(23, 66, 69, 14);
		mainPanel.add(lastNameLabel);
		
		//SaveButtonAction saveButton = new SaveButtonAction();
		//saveButton.setSaveButtonAction();
		
		//ExitButtonAction exit = new ExitButtonAction();
		//exit.exitButtonAction();
		
		buttonsAction();
		buttonExit.setBounds(133, 134, 92, 21);
		mainPanel.add(buttonExit);
		
	}


	
	public void buttonsAction() {
		//save button
		save.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				saveFirstName = textFieldFirstName.getText();
				saveLastName = textFieldLastName.getText();
				
				
				SaveXmlInfo savePersonInfo = new SaveXmlInfo();
				savePersonInfo.saveToXmlPerson(saveFirstName, saveLastName);
				

				System.out.println("Registration done");
				
			}
		});
		//exit button
		this.buttonExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
	}



	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}


/*	public void showRegistration() throws IOException {
		fileReader = new  FileReader("d:/studentRegistration.txt");
		readRegistration = new BufferedReader(fileReader);
		String line = null;
		while((line = readRegistration.readLine()) != null) {
			System.out.println("Data Base File: \n " + line);
			
		}
	}
	*/
	
}
